package org.road0329.dlt698.sessionlayer.hdlc;

import java.nio.ByteBuffer;
import java.util.Optional;

public class HdlcAddressPair {
    private ByteBuffer cliAddr = null;
    private HdlcAddress srvAddr = null;

    public HdlcAddressPair(HdlcAddress srvAddr, ByteBuffer cliAddr) {
        this.cliAddr = cliAddr;
        this.srvAddr = srvAddr;
    }

    public ByteBuffer getCliAddr() {
        return Optional.ofNullable(cliAddr)
                .orElseThrow(() -> new IllegalStateException("cliAddr is null"));
    }

    public HdlcAddress getSrvAddr() {
        return Optional.ofNullable(srvAddr)
                .orElseThrow(() -> new IllegalStateException("srvAddr is null"));
    }

    public HdlcAddressPair switchedPair() {
        if (srvAddr != null && cliAddr != null) {
            return new HdlcAddressPair(srvAddr, cliAddr);
        } else {
            throw new IllegalStateException("srvAddr or cliAddr is null");
        }
    }

    @Override
    public String toString() {
        if (cliAddr != null && srvAddr != null) {
            return cliAddr.toString() + ":" + srvAddr.toString();
        } else {
            return "cliAddr or srvAddr is null";
        }
    }
}



